package com.zfdang.touchhelper.tool;

import android.graphics.Rect;
import android.view.accessibility.AccessibilityNodeInfo;

import java.util.Locale;

/**
 * @author Aivin
 * created on 2023/11/9
 * des:
 */
public class LyAccessibilityTool {
    /**
     * 获取节点的信息。对应的类名，坐标，文本值等
     */
    public static String getDescribeOfAccessibilityNode(AccessibilityNodeInfo nodeInfo) {
        if (nodeInfo == null) {
            return "null";
        }

        String result = "Node";
        result += " class =" + nodeInfo.getClassName().toString();

        final Rect rect = new Rect();
        nodeInfo.getBoundsInScreen(rect);
        result += String.format(Locale.getDefault(), " Position=[%d, %d, %d, %d]", rect.left, rect.right, rect.top, rect.bottom);

        CharSequence id = nodeInfo.getViewIdResourceName();
        if (id != null) {
            result += " ResourceId=" + id;
        }

        CharSequence description = nodeInfo.getContentDescription();
        if (description != null) {
            result += " Description=" + description;
        }

        CharSequence text = nodeInfo.getText();
        if (text != null) {
            result += " Text=" + text;
        }

        return result;
    }
}
